const path = require('path')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
module.exports = {
    devtool: 'none',
    mode: 'none',
    devServer: {
        contentBase: './dist',
        hot: true,
        open: true
      },
    entry: {
        app: [
            './src/main.js'
        ]
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/[name].js',
        publicPath: '/',
        chunkFilename: 'js/[name].js'
    },
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: "vue-loader",
                exclude: /node_modules/
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: file => (
                    /node_modules/.test(file) &&
                    !/\.vue\.js/.test(file)
                )
            },
            {
                test: /\.css$/i,
                use: ["vue-style-loader", "css-loader"],
            },
            {
                test: /\.less$/,
                use: [
                    'vue-style-loader',
                    'css-loader',
                    'less-loader'
                ]
            },
            {
                test: /\.(png|jpe?g|gif)$/i,
                use: [
                    {
                        loader: 'file-loader',
                        options: {
                            esModule: false,
                            name: 'img/[name].[hash:8].[ext]',
                        },
                    },

                ],
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            title: 'vue demo',
            template: 'public/index.html'
        }),
        new webpack.DefinePlugin(
            {
                BASE_URL: "'/'"
            }
        ),
        new VueLoaderPlugin(),
        new CopyPlugin(
            [
                {
                    from: path.resolve(__dirname, 'public'),
                    to: path.resolve(__dirname, 'dist'),
                    toType: 'dir',
                    ignore: [
                        '.DS_Store',
                        {
                            glob: 'index.html',
                            matchBase: false
                        }
                    ]
                }
            ]
        )
    ]
}
